Socket
Socket
Sign inDemoInstall

@cosmjs/crypto

Package Overview
Dependencies
Maintainers
2
Versions
107
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cosmjs/crypto

Cryptography resources for blockchain projects


Version published
Weekly downloads
219K
increased by4.31%
Maintainers
2
Weekly downloads
 
Created

What is @cosmjs/crypto?

@cosmjs/crypto is a JavaScript library that provides cryptographic utilities for use in blockchain applications, particularly those built on the Cosmos SDK. It includes functions for hashing, signing, and verifying data, as well as generating and managing cryptographic keys.

What are @cosmjs/crypto's main functionalities?

Hashing

This feature allows you to hash data using the SHA-256 algorithm. The code sample demonstrates how to hash a string and output the hash in hexadecimal format.

const { sha256 } = require('@cosmjs/crypto');
const data = new TextEncoder().encode('Hello, world!');
const hash = sha256(data);
console.log(Buffer.from(hash).toString('hex'));

Key Generation

This feature allows you to generate random cryptographic keys. The code sample demonstrates how to generate a 32-byte private key and output it in hexadecimal format.

const { Random } = require('@cosmjs/crypto');
const privateKey = Random.getBytes(32);
console.log(Buffer.from(privateKey).toString('hex'));

Signing

This feature allows you to sign data using the Secp256k1 algorithm. The code sample demonstrates how to sign a hashed message and output the signature in hexadecimal format.

const { Secp256k1, sha256 } = require('@cosmjs/crypto');
const privateKey = Random.getBytes(32);
const message = new TextEncoder().encode('Hello, world!');
const hash = sha256(message);
const signature = Secp256k1.createSignature(hash, privateKey);
console.log(Buffer.from(signature.toFixedLength()).toString('hex'));

Verification

This feature allows you to verify signatures using the Secp256k1 algorithm. The code sample demonstrates how to verify a signature and output whether it is valid.

const { Secp256k1, sha256 } = require('@cosmjs/crypto');
const privateKey = Random.getBytes(32);
const publicKey = Secp256k1.makeKeypair(privateKey).pubkey;
const message = new TextEncoder().encode('Hello, world!');
const hash = sha256(message);
const signature = Secp256k1.createSignature(hash, privateKey);
const isValid = Secp256k1.verifySignature(signature, hash, publicKey);
console.log(isValid);

Other packages similar to @cosmjs/crypto

FAQs

Package last updated on 25 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc